<template>
  <el-card>
    <!-- ! 操作区域 -->
    <el-row type="flex" justify="space-between">
      <div>
        <el-button size="small" type="primary">新增</el-button>
      </div>
      <div>右侧内容</div>
    </el-row>
    <!-- ! 表格区域 -->
    <el-table :data="list" border row-key="id">
      <el-table-column prop="title" label="菜单名称"></el-table-column>
      <el-table-column prop="path" label="菜单地址"></el-table-column>
      <el-table-column prop="mark" label="权限标识"></el-table-column>
      <el-table-column prop="icon" label="图标"></el-table-column>
      <el-table-column prop="component" label="组件路径"></el-table-column>
      <el-table-column prop="component" label="类型">
        <template slot-scope="scope">
          <el-tag type="primary" v-if="scope.row.type === 1">菜单</el-tag>
          <el-tag type="success" v-if="scope.row.type === 2">按钮</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="success"
            size="small"
            circle
            icon="el-icon-edit"
            @click="editRow(scope.row.id)"
          ></el-button>
          <el-button
            type="warning"
            size="small"
            circle
            icon="el-icon-plus"
          ></el-button>
          <el-button
            type="danger"
            size="small"
            circle
            icon="el-icon-delete"
            @click="delRow(scope.row.id)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- ! 新增修改区域 -->
  </el-card>
</template>
<script>
import { getAllMenuListApi } from '@/api/menu'
export default {
  components: {},
  name: 'User',
  data() {
    return {
      list: [] // 表格数据
    }
  },
  created() {
    this.initData()
  },
  methods: {
    // 获取表格数据
    async initData() {
      const res = await getAllMenuListApi()
      this.list = res
    },
    // 删除事件
    async delRow(id) {
      try {
        await this.confirm('确认删除吗？')
      } catch (error) {
        return console.log(error)
      }
      // await delUserApi(id)
      this.message.success('删除成功')
      if (this.queryData.page > 1 && this.list.length === 1) {
        this.queryData.page--
      }
      this.initData()
    },
    // 修改事件
    editRow(id) {
      // this.refs.addUser.getRowInfo(id)
    }
  }
}
</script>
<style scoped></style>
